﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FurnitureSystem
{
    public partial class frmManagerUser : Form
    {
        public static string staffid;
        public frmManagerUser()
        {
            InitializeComponent();
        }

        private void frmManagerUser_Load(object sender, EventArgs e)
        {
            loadlaidulieu();
            if (frmLogin.depart != "admin     ") { btnEdit.Enabled = false; btnDelete.Enabled = false; }
        }
        public void loadlaidulieu() {
            SqlConnection conn = connect.Getconect();
            conn.Open();
            string sql = "select * from EmployeeDetail";
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
            conn.Close();
        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            frmRegister reg = new frmRegister();
            reg.Show();
            this.Hide();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            staffid = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            frmEdit edit = new frmEdit();
            edit.Show();
            this.Hide();
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            
            staffid = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            
            frmView fv = new frmView();
            fv.Show();
            this.Hide();

        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            staffid = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            SqlConnection conn = connect.Getconect();
            conn.Open();
            DialogResult ketqua = MessageBox.Show("Bạn có chắc chắn muốn xóa?","Thông báo",MessageBoxButtons.YesNo);
            if (ketqua == DialogResult.Yes)
            {
            string sql="delete from EmployeeDetail where staffid='"+staffid+"'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader sdr = cmd.ExecuteReader();
            loadlaidulieu();
            MessageBox.Show("Delete success");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
            frmMain frm = new frmMain();
            frm.Show();
        }
    }
}
